﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.ServiceModel.Syndication;

namespace IndyMosaic.Models.Syndication
{
    public static class Extensions
    {
        public static string GetRss20Feed(this SyndicationFeed feed)
        {
            StringBuilder xmlString = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(xmlString);
            var formatter = feed.GetRss20Formatter(false);
            formatter.PreserveElementExtensions = true;
            formatter.PreserveAttributeExtensions = true;
            
            formatter.WriteTo(writer);
            writer.Close();
            
            return xmlString.ToString();
        }

        public static string GetAtomFeed(this SyndicationFeed feed)
        {
            StringBuilder xmlString = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(xmlString);
            feed.GetAtom10Formatter().WriteTo(writer);
            writer.Close();

            return xmlString.ToString();
        }

    }
}
